#include "SettingBarButton.h"

SettingBarButton::SettingBarButton(QString iconName, QWidget* parent)
{
	this->setParent(parent);
	this->resize(parent->width(), parent->width());
	this->setCursor(Qt::PointingHandCursor);
	this->setMouseTracking(true);
	this->defaultStyle();
	this->m_iconName = iconName;
	this->changeIcon(this->m_iconName);
}

void SettingBarButton::check()
{
	this->m_checked = true;
	this->checkStyle();
	this->changeIcon(this->m_iconName + "_checked");
}

void SettingBarButton::uncheck()
{
	this->m_checked = false;
	this->defaultStyle();
	this->changeIcon(this->m_iconName);
}

void SettingBarButton::disable()
{
	// this->setDisabled(true);
	this->setCursor(Qt::ForbiddenCursor);
}

void SettingBarButton::enable()
{
	// this->setEnabled(true);
	this->setCursor(Qt::PointingHandCursor);
}

bool SettingBarButton::checked() const
{
	return this->m_checked;
}

SettingBarButton::~SettingBarButton()
{
}

void SettingBarButton::enterEvent(QEnterEvent* ev)
{
	this->checkStyle();
}

void SettingBarButton::leaveEvent(QEvent* ev)
{
	if (!this->m_checked) {
		this->defaultStyle();
	}
	
}

void SettingBarButton::changeIcon(QString icon)
{
	this->setIcon(QIcon("./icon/" + icon + ".png"));
	this->setIconSize(QSize(0.6 * this->width(), 0.6 * this->height()));
}

void SettingBarButton::defaultStyle()
{
	this->setStyleSheet("background-color: transparent;");
}

void SettingBarButton::checkStyle()
{
	this->setStyleSheet("background-color: #b8f8e6; border: none; border-radius:5px;");
}
